package br.edu.ufcg.dsc.actions.resource;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.resource.Issue;
import br.edu.ufcg.dsc.services.ResourceService;

import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/issue.jsp")
public class FindIssueAction extends ResourceDriven<Issue> implements Preparable {

	private static final long serialVersionUID = 1L;
	private int resourceId;
	private Issue issue;

	@Override
	public String execute() {
		return SUCCESS;
	}

	public Issue getIssue() {
		return issue;
	}

	public void setIssue(Issue issue) {
		this.issue = issue;
	}

	public void prepare() throws Exception {
		Resource resource = ResourceService.find(resourceId);
		if (resource != null)
			issue = new Issue(resource.getMarc());
		else issue = new Issue();
	}

	public Issue createModel() {
		return issue;
	}
	
	
}
